<template>
  <li class="todo-item" :class="{ completed: todo.completed }">
    <div class="todo-content">
      <input 
        type="checkbox" 
        :checked="todo.completed" 
        @change="$emit('toggle')"
        class="todo-checkbox"
      />
      <span class="todo-text" :class="{ completed: todo.completed }">
        {{ todo.text }}
      </span>
    </div>
    <button @click="$emit('remove')" class="delete-button">
      删除
    </button>
  </li>
</template>

<script setup>
// 定义props
const props = defineProps({
  todo: {
    type: Object,
    required: true
  }
});

// 定义事件
defineEmits(['toggle', 'remove']);
</script>

<style scoped>
.todo-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  margin-bottom: 10px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.todo-item:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.todo-item.completed {
  opacity: 0.7;
  background-color: #f9f9f9;
}

.todo-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.todo-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.todo-text {
  font-size: 16px;
  color: #333;
  transition: all 0.3s ease;
}

.todo-text.completed {
  text-decoration: line-through;
  color: #888;
}

.delete-button {
  padding: 6px 12px;
  background-color: #ff4757;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  opacity: 0.8;
}

.delete-button:hover {
  opacity: 1;
  background-color: #ff6b81;
}
</style> 